import { isObject } from "@/shared";
import { reactive } from "./reactive.js";
import {track,trigger} from "./effect.js"


export function ref(val){
    return new RefImp(val);
}

class RefImp {
    constructor(val){
        if(convert(val)){
            this._val = reactive(val)
        }
        this._val = val;
    }

    get value(){  //加了get value直接用函数名调用不用小括号调用
        track(this,'get','value')
        return this._val;
    }  
    
    set value(newVal){
        if(this._val!==newVal){
            this._val=newVal
            trigger(this,'set','value')
        }
    
}
}

function convert(val){
    return isObject(val) ? reactive(val):val
}

const n = ref(1)

